% The main use of this function is to Compute Profit Y by wwb June 6th

function Y = profit(Q,R,r,ci)
ci = 40 ; cI = 200; r = 100;
Income = 0; Loss = 0;

% There are two parts of Y.
% Firstly, we compute the income.
for i = 1:8
    siz = size(Q);
    length = siz(2);
    for m = 1:length
        Income = Income + (m-1)*Q(i,m);
    end
end

% Secondly, we compute Losses.
for i = 1:8
    volume = size(R);
    len = volume(2);
    for mm = 1:len
        Loss = Loss + (mm-1)*R(i,mm);
    end
end

% Finally we get the profit!
Y = Income - Loss;
end